package cn.z2huo.demo.mybatis.plus.dao;

import cn.z2huo.demo.mapper.role.RoleMapper;
import cn.z2huo.demo.model.dataobject.role.RoleDO;
import cn.z2huo.demo.mybatis.plus.mapper.CustomRoleMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RoleDAO {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private CustomRoleMapper customRoleMapper;

    public List<RoleDO> listRoleByCodeAndName(List<RoleDO> roleDOList) {
        if (CollectionUtils.isEmpty(roleDOList)) {
            return List.of();
        }
        if (roleDOList.stream().anyMatch(roleDO -> StringUtils.isBlank(roleDO.getRoleName()) || StringUtils.isBlank(roleDO.getRoleCode()))) {
            return List.of();
        }

        return customRoleMapper.listRoleByCodeAndName(roleDOList);

//        List<Object[]> collect = roleDOList.stream().map(roleDO -> new Object[]{roleDO.getRoleCode(), roleDO.getRoleName()}).toList();
//        QueryWrapper<RoleDO> wrapper = Wrappers.query(RoleDO.class);
//        wrapper.in("(role_code, role_name)", collect);
//        return roleMapper.selectList(wrapper);
    }


}
